package com.lai.hospital.controller;

import com.lai.hospital.annotation.OptLog;
import com.lai.hospital.constant.OptTypeConst;
import com.lai.hospital.dto.ConfirmAppointmentDTO;
import com.lai.hospital.dto.DoctorDTO;
import com.lai.hospital.dto.MyDoctorDTO;
import com.lai.hospital.dto.RecommendedDoctorDTO;
import com.lai.hospital.entity.Doctor;
import com.lai.hospital.service.DoctorService;
import com.lai.hospital.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;

/**
 * @author : lai
 * @version V1.0
 * @Project: hospital-springboot
 * @Package com.lai.hospital.controller
 * @Description: 医生控制器
 * @date Date : 2022年11月24日 21:16
 */
@RestController
@Api(value = "医生模块")
public class DoctorController {

    @Autowired
    private DoctorService doctorService;


    @GetMapping("/admin/listDoctor")
    @ApiOperation(value = "获取医生列表")
    //当前端传来的值，不是个完整的对象，只是包含了 Req 中的部分参数时，不需要@RequestBody  conditionVO前端通常只传keywords字段
    public Result<PageResult<DoctorDTO>> listDoctor(ConditionVO conditionVO){
        return Result.ok(doctorService.listDoctor(conditionVO));
    }

    @OptLog(optType = OptTypeConst.SAVE_OR_UPDATE)
    @PostMapping("/admin/saveOrUpdateDoctor")
    @ApiOperation(value = "添加或修改医生")
    public Result<?> saveOrUpdateDoctor(@Valid @RequestBody DoctorVO doctorVO){
        doctorService.saveOrUpdateDoctor(doctorVO);
        return Result.ok();
    }

    /**
     * 更新医生头像
     * @param file 文件
     * @return {@link Result<String>} 医生头像地址
     */
    @ApiOperation(value = "更新医生头像")
    @ApiImplicitParam(name = "file", value = "医生头像", required = true, dataType = "MultipartFile")
    @PostMapping("/admin/doctor/avatar")
    public Result<String> updateUserAvatar(MultipartFile file) {
        return Result.ok(doctorService.updateDoctorAvatar(file));
    }

    /**
     * 删除医生
     * @param id 医生id
     */
    @ApiOperation(value = "删除医生")
    @DeleteMapping("/admin/deleteDoctor/{id}")
    public Result<?> deleteDoctor(@PathVariable("id") Integer id){
        doctorService.deleteDoctor(id);
        return Result.ok();
    }

    /**
     * 根据用户id查询医生信息
     */
    @ApiOperation(value = "根据用户id查询医生信息")
    @GetMapping("/doctor/info")
    public Result<Doctor> doctorInfo(){

        return Result.ok(doctorService.doctorInfo());
    }

    /**
     * 获取推荐医生列表
     * @param userId 用户id
     * @return 医生列表
     */
    @GetMapping("/user/listRecommendedDoctor")
    @ApiOperation(value = "获取推荐医生列表")
    public Result<List<RecommendedDoctorDTO>> listRecommendedDoctor(Integer userId){
        // 查询用户预约过哪些科室，推荐这些科室的医生
        return Result.ok(doctorService.listRecommendedDoctor(userId));
    }

    /**
     * 获取我的医生列表
     * @param userId 用户id
     */
    @GetMapping("/user/listMyDoctor")
    @ApiOperation(value = "获取我的医生列表")
    public Result<List<MyDoctorDTO>> listRecommendedDoctor(Integer userId, Integer num){
        // 查询用户预约过哪些科室，推荐这些科室的医生
        return Result.ok(doctorService.listMyDoctor(userId, num));
    }

    /**
     * 获取医生信息根据id
     * @param id 医生id
     */
    @GetMapping("/user/doctorInfo/{id}")
    @ApiOperation(value = "获取医生信息")
    public Result<DoctorDTO> getDoctorInfoById(@PathVariable("id")Integer id){
        // 查询用户预约过哪些科室，推荐这些科室的医生
        return Result.ok(doctorService.getDoctorInfoById(id));
    }

    /**
     * 查询出指定科室、指定日期有排班信息的医生
     * @param departmentDoctorScheduleVO 条件vo
     */
    @GetMapping("/user/schedule/department/doctor")
    @ApiOperation(value = "查询出指定科室、指定日期有排班信息的医生")
    public Result<List<Doctor>> getDoctorByDepartmentAndScheduleDate(DepartmentDoctorScheduleVO departmentDoctorScheduleVO){
        return Result.ok(doctorService.getDoctorByDepartmentAndScheduleDate(departmentDoctorScheduleVO));
    }

    /**
     * 确认预约  根据医生id获取医院  科室
     * @return
     */
    @GetMapping("/user/confirmAppointmentPreview")
    @ApiOperation(value = "确认预约")
    public Result<ConfirmAppointmentDTO> confirmAppointment(AppointmentPreviewVO appointmentPreviewVO){
        return Result.ok(doctorService.confirmAppointment(appointmentPreviewVO));
    }

}
